<?php


namespace App\Http\Controllers\Admin;


use App\DTOS\Admin\UserRoleDTO;
use App\Http\Controllers\Controller;
use App\Services\Game\UserMemberService;
use App\Services\Game\UserRoleService;
use App\Utils\MyLog;
use App\Utils\ResponseUtil;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;


class LogRolePetController extends Controller
{
    private Request $request;
    private UserRoleService $userRoleService;
    private UserMemberService $userMemberService;

    /**
     * EquipmentController constructor.
     * @param Request $request
     * @param UserRoleService $userRoleService
     * @param UserMemberService $userMemberService
     */
    public function __construct(Request $request, UserRoleService $userRoleService, UserMemberService $userMemberService)
    {
        $this->request = $request;
        $this->userRoleService = $userRoleService;
        $this->userMemberService = $userMemberService;
    }


    public function paginate(){ //查询ES数据库
        global $gameArea;
        $params = request()->all();
        $roleName = data_get($params,'roleName');

        if ($roleName){
            $gameRoleDTO = new UserRoleDTO(['nick'=>$roleName]);
            $userRolePaginate = $this->userRoleService->paginate($gameRoleDTO);
            if (empty($userRolePaginate->items())){
                throw new \Exception("没有数据..");
            }
            $roleIds = collect($userRolePaginate->items())->pluck('id')->unique()->toArray();
            $params['roleIds'] = $roleIds;
        }
        MyLog::error(date("Y-m-d H:i:s")."  请求参数: " . json_encode($params));
        $result = callRpc('/RolePetLogService/paginate',$params,['gameArea'=>$gameArea]);
        // snap_time
        if($result){
        foreach($result['data'] as &$item){
            $item['rolepet_datetime'] = date("Y-m-d H:i:s");
            $item['action_type']=$this->actionTypeName($item['action_type']);
        }
        }
        return ResponseUtil::json($result);
    }


    private function actionTypeName($actionType){
        switch($actionType){
            case 1: return '使用';
            case 2: return '精灵转生';
            case 3: return '精灵进化';
            case 4: return '精灵属性洗练';
            case 5: return '精灵技能洗练';
            case 6: return '精灵仓库学习';
            case 7: return '精灵仓库开格';
            default: return '';
        }
    }

}
